package com.foo.common.base.service;

import java.io.Serializable;
import java.util.List;

import org.hibernate.SessionFactory;

import com.foo.common.base.pojo.FooGenericSearch;
import com.foo.common.base.pojo.FooGenericSearchResult;
import com.foo.common.base.pojo.FooGenericTransactionModel;

public interface FooGenericService {

	/**
	 * Remove a persistent instance from the datastore. The argument may be an
	 * instance associated with the receiving <tt>Session</tt> or a transient
	 * instance with an identifier associated with existing persistent state.
	 * This operation cascades to associated instances if the association is
	 * mapped with {@code cascade="delete"}
	 * 
	 * @param object
	 *            the instance to be removed
	 */
	public void delete(Object object);

	public void saveOrUpdate(Object object);

	/**
	 * <p>
	 * If the id of the entity is null or zero, add it to the datastore and
	 * assign it an id; otherwise, update the corresponding entity in the
	 * datastore with the properties of this entity. In either case the entity
	 * passed to this method will be attached to the session.
	 * 
	 * <p>
	 * If an entity to update is already attached to the session, this method
	 * will have no effect. If an entity to update has the same id as another
	 * instance already attached to the session, an error will be thrown.
	 * 
	 * @return <code>true</code> if create; <code>false</code> if update.
	 */
	public Serializable save(Object object);

	public <T> void batchSave(List<T> object);

	/**
	 * Returns a <code>SearchResult</code> object that includes both the list of
	 * results like <code>search()</code> and the total length like
	 * <code>count()</code>.
	 * 
	 * @param T
	 *            The result type is automatically determined by the context in
	 *            which the method is called.
	 */

	public FooGenericSearchResult searchAndCount(FooGenericSearch search);

	/**
	 * Flushes changes in the Hibernate session to the datastore.
	 */
	public void flush();

	public void doInTransaction(
			FooGenericTransactionModel fooGenericTransactionModel);

	/**
	 * 此种模式中maxResult必须指定，否则报错
	 * 
	 * @param fooGenericSearch
	 * @return
	 * @throws Exception
	 */
	public <T> List<T> list(FooGenericSearch fooGenericSearch);

	/**
	 * 获得hql指定的全部条件的时候调用此方法。需要精确指定查询调用:
	 * 
	 * @see List<T> list(FooGenericSearch fooGenericSearch)
	 * @param hql
	 * @return
	 */
	public <T> List<T> list(String hql);

	/**
	 * 加入到2级缓存服务中，测试功能
	 * 
	 * @param hql
	 * @return
	 */

	public SessionFactory getSessionFactory();

	public String logSummary();

	/**
	 * 只读取list的第一个个元素
	 */
	public <T> T getObject(String hql);

	public int count(String hql);

	/**
	 * For primary id reading and loading only
	 * 
	 * @param clazz
	 * @param id
	 * @return
	 */
	public <T> T get(Class<T> clazz, Serializable id);

	public void update(Object entity);

	public int executeHql(String sql);

	public <T> void evictEntityRegion(Class<T> entityClass);

	public <T> void evictQueryRegion(String regionName);
}
